
package com.udc.medLine.transaction;

import java.util.List;

import com.udc.medLine.entity.CondicaoVO;
import com.udc.medLine.entity.Funcionario;
import com.udc.medLine.entity.Status;
import com.udc.medLine.factory.FactoryFuncionario;
import com.udc.medLine.factory.FactoryStatus;
import com.udc.medLine.persistence.Bd;

public class TransactionStatus {

	private Status status;
	private List listStatus;
	private Bd banco;
	
	/**
	 * 
	 */
	public TransactionStatus() {
		super();
		status = new Status();
		try{
			banco = Bd.getInstance();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		// TODO Stub de construtor gerado automaticamente
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status new_status) {
		this.status = new_status;
	}

	public void remover(Status nStatus) throws Exception {
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();
			status.setId(nStatus.getId());
			factory.setStatus(status);
			factory.delete();
		banco.commit();
	}

	public void inserir(Status nStatus) throws Exception {
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();			
			status.setNome(nStatus.getNome());
			factory.setStatus(status);
			factory.insert();
		banco.commit();
	}

	public void atualizar(Status nStatus) throws Exception {
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();
			status.setId(nStatus.getId());
			status.setNome(nStatus.getNome());
			factory.setStatus(status);
			factory.update();
		banco.commit();
	}


	public void obterStatus(String campo, String valor) throws Exception{
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();
			factory.setStatus(new Status());
			listStatus = factory.getStatus(campo,valor);
		banco.commit();
	}
	
	public void obterListaStatus() throws Exception{
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();
			factory.setStatus(new Status());
			listStatus = factory.getListaStatus();
		banco.commit();
	}
	
	public void obterStatus(Status nStatus) throws Exception{
		banco.beginTransaction();
			FactoryStatus factory = new FactoryStatus();
			status.setId(nStatus.getId());
			factory.setStatus(status);
			status = factory.obterStatus();
		banco.commit();
	}
	
	/**
	 * @return
	 */
	public List getListStatus() {
		return listStatus;
	}

	/**
	 * @param list
	 */
	public void setListStatus(List list) {
		listStatus = list;
	}

	public List<Status> search(CondicaoVO condicao) throws Exception {
		banco.beginTransaction();
		FactoryStatus factory = new FactoryStatus();
		listStatus = factory.search(condicao);
		banco.commit();
		return listStatus;
	}

}
